//
//  TextViewLogFormatter.m
//  LogManagerDemo
//
//  Created by US bike on 2017/7/25.
//  Copyright © 2017年 US bike. All rights reserved.
//

#import "TextViewLogFormatter.h"
#import <Foundation/Foundation.h>

@implementation TextViewLogFormatter


- (NSString *) formatLogMessage:(DDLogMessage *)logMessage {
    
    //获取文件名
    NSString *locationString;
    NSArray *pathArray = [logMessage ->_file componentsSeparatedByString:@"/"];
    if ([pathArray count] > 0) {
        locationString = pathArray.lastObject;
    } else {
        locationString = @"No File";
    }
    
    //时间
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    [formatter setDateFormat:@"HH:mm:ss"];
    NSString *timeStr = [formatter stringFromDate:[NSDate date]];
    

    NSString *messageStr = @"";
    switch (logMessage->_flag) {
        case DDLogFlagError:
        case DDLogFlagWarning:
            messageStr = [NSString stringWithFormat:@"%@ %@[%lu行] %@ %@", timeStr, locationString, (unsigned long)logMessage->_line, logMessage->_function, logMessage->_message];
            break;
            
        case DDLogFlagInfo:
        case DDLogFlagDebug:
        case DDLogFlagVerbose:
            messageStr = [NSString stringWithFormat:@"%@  %@", timeStr, logMessage->_message];
            break;
            
        default:
            break;
    }
    
    return messageStr;
    
}



@end
